var _Step = require('scenes/game/toturial/step.js');
var _inherit = require('core/inherit.js');
var _global = require('global/global.js');

var TWEEN = require('third_party/tweenjs/tween.js');
var _Helper = require('third_party/tweenjs/helper.js');
var _Constant = require('scenes/game/constant.js');

var MOVE_LEFT = 0;
var MOVE_TOP = 1;
var MOVE_RIGHT = 2;
var MOVE_BOTTOM = 3;

var OFFSET = 300;

function Step() {
    _Step.call(this);

    this.mVec = _Helper.createPoint();
    this.mVec.setDirection(-1, 0);

    this.move1 = -OFFSET;
    this.move2 = -OFFSET + _Constant.slotSize[0];
}
_inherit(Step, _Step);
Step.prototype.onUpdate = function () {
    this.mS1.slideIn(MOVE_LEFT, this.mVec.getPosition(this.move1));
    this.mS2.slideIn(MOVE_LEFT, this.mVec.getPosition(this.move2));
};
Step.prototype.onComplete = function () {
    this.mGameArea.resetTouch();
    this.mGameArea.setTouchEnable(true);
    this.mToturial.nextStep();

    this.mS1 = null;
    this.mS2 = null;
    this.mGameArea = null;
    this.mCells = null;
    this.mLocal = null;
    this.mToturial = null;
};
Step.prototype.onStart = function (toturial, local) {
    this.mToturial = toturial;
    this.mLocal = local;
    this.mGameArea = local.find('gamearea');
    this.mCells = local.find('gamearea.cells');

    this.mGameArea.setTouchEnable(false);
    this.mCells.predictMerge(MOVE_LEFT);

    this.mS1 = this.mCells.getSlotRowCol(1, 1);
    this.mS1.bindCell(this.mGameArea.createCell(1));
    this.mS2 = this.mCells.getSlotRowCol(2, 2);
    this.mS2.bindCell(this.mGameArea.createCell(2));

    this.mCells.prepareMove();

    new TWEEN.Tween(this)
        .to({move1: 0, move2: 0}, 0.25)
        .onUpdate(this.onUpdate)
        .onComplete(this.onComplete)
        .easing(TWEEN.Easing.Cubic.Out)
        .start();

    var rtf = this.rtfHeader().textBuilder()
        .addText('Meet ', 'black')
        .addText('1', 'green')
        .addText(' & ', 'black')
        .addText('2', 'red')
        .create();
    this.alineRight(rtf);
    toturial.showHeaderTip(rtf);
    toturial.showFooterTip('SWIPE ANYWHERE TO MOVE THEM');
};

module.exports = Step;